# coding:Utf-8
from appium import webdriver
from time import sleep
import unittest
from model.HTMLTestRunner_cn import HTMLTestRunner
import os


class Demo1(unittest.TestCase):
    def setUp(self):
        devices = "192.168.11.22:6666"
        # devices = "192.168.123.170:6666"
        caps = {}
        caps["platformName"] = "android"
        caps["deviceName"] = devices
        caps["appPackage"] = "com.xqxc.customer"
        caps["appActivity"] = "com.xqxc.home_module.ui.activity.MainActivity"
        # caps["autoGrantPermissions"] = True
        caps["noReset"] = True
        caps["skipServerInstallation"] = True
        caps["skipDeviceInitialization"] = True

        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
        self.imgs=[]
    def add_img(self):
        self.imgs.append(self.driver.get_screenshot_as_base64())
        return True
    def tearDown(self):
        self.driver.quit()

    def test_case001(self):
        el3 = self.driver.find_element_by_id("com.xqxc.customer:id/iv_search")
        el3.click()
        el4 = self.driver.find_element_by_id("com.xqxc.customer:id/et_search")
        self.add_img()
        el4.click()
        el4.send_keys("测试")
        self.driver.keyevent("66")
        return self


if __name__ == "__main__":
    suites = unittest.TestSuite()
    suites.addTest(Demo1("test_case001"))
    runner = HTMLTestRunner(
        title="带截图和日志的测试报告",
        description="带截图和日志的测试报告",
        stream=open("./report/report.html","wb"),
        verbosity=2,
        retry=2,
        save_last_try=True
    )
    runner.run(suites)
